﻿@{
    ViewBag.Title = "";
}
<script type="text/javascript">
    //树
    var zNodes_Permission_Workgroup_SelectStaff = [];
    var clickState_Permission_Workgroup_SelectStaff = false; //标识是否选择了节点
    var zTree1_Permission_Workgroup_SelectStaff;
    var setting_Permission_Workgroup_SelectStaff;
    var tempID = 0; //记录选中节点的id
    var tempName = ""; //记录选中节点名称
    var FromOrg_Permission_Workgroup_SelectStaff = 0; //1代表该节点来自组织机构，2代表来自岗位
    setting_Permission_Workgroup_SelectStaff = {
        checkable: false,
        async: true,
        isSimpleData: true,
        asyncUrl: "/Permission/Organize/GetOrganizeNodes/1",  //获取节点数据的URL地址,1代表含有职员
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "Name",
        open: false,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_Permission_Workgroup_SelectStaff,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_Permission_Workgroup_SelectStaff
        }
    };

    function zTreeOnAsyncSuccess_Permission_Workgroup_SelectStaff(event, treeId, treeNode, msg) {
        //异步成功
    }

    //树的单击事件
    function zTreeOnClick_Permission_Workgroup_SelectStaff(event, treeId, treeNode) {
        tempID = treeNode.Id.substring(2, treeNode.Id.length);
        tempName = treeNode.Name;
        clickState_Permission_Workgroup_SelectStaff = true;
        if (treeNode.Id.substring(0, 2) == "C_")
            FromOrg_Permission_Workgroup_SelectStaff = 1;
        else if (treeNode.Id.substring(0, 2) == "D_")
            FromOrg_Permission_Workgroup_SelectStaff = 2;
    }

    $(document).ready(function () {
        refreshTree_Permission_Workgroup_SelectStaff("/Permission/Organize/GetOrganizeNodes/1");

    });
    function refreshTree_Permission_Workgroup_SelectStaff(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_Permission_Workgroup_SelectStaff.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree1_Permission_Workgroup_SelectStaff = $("#tree_Permission_Workgroup_SelectStaff").zTree(setting_Permission_Workgroup_SelectStaff, zNodes_Permission_Workgroup_SelectStaff);
    }
    $("#btnSave_Permission_Workgroup_SelectStaff").click(function () {
        if (!clickState_Permission_Workgroup_SelectStaff) {//如果没有选择节点就不能点击确定按钮
            alertMsg.error("请选择节点！");
            return false;
        }
        var selectedNode = zTree1_Permission_Workgroup_SelectStaff.getSelectedNode();
        //选择的节点只能是职员，并回传建立职员与工作组之间的关系
        if (selectedNode.Mark == "Staff") {
            var workgroupId = $("#workgroupId_Permission_Workgroup_SelectStaff").val();
            $.post("/Permission/Workgroup/CreateConnectionWorkgroupAndStaff", { workgroupId: workgroupId, staffId: selectedNode.Id.substring(2, selectedNode.Id.length) }, StaffAdded_Permission_Workgroup, "json");
        } else {
            alertMsg.error("请选择职员！");
            return false;
        }
    });
</script>
<div class="pageContentD">
    <div class="pageFormContent" layouth="60">
        <ul id="tree_Permission_Workgroup_SelectStaff" class="ztree">
        </ul>
        <input type="hidden" id="workgroupId_Permission_Workgroup_SelectStaff" value="@ViewBag.WorkgroupId" />
    </div>
    <div class='formBar'>
        <ul>
            <li>
                <button type="button" class="btn btn-success btn-sm" id="btnSave_Permission_Workgroup_SelectStaff">
                    确定</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm">
                    取消</button>
            </li>
        </ul>
    </div>
</div>
